FROM centos:7

# version
ENV PHP 7.2.2
ENV PHPREDIS_VERSION 4.0.1
ENV SWOOLE_VERSION 4.4.0
ENV EASYSWOOLE_VERSION 3.x

MAINTAINER manlin

# Timezone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo 'Asia/Shanghai' > /etc/timezone

RUN mkdir -p /var/www/code && mkdir -p /usr/local/webserver

WORKDIR /var/www/code

RUN yum install epel-release -y && \
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel \
    libcurl-devel libjpeg-devel libpng-devel openssl-devel \
    libmcrypt-devel libxslt-devel libtidy-devel autoconf \
    iproute net-tools telnet wget curl git rpm zip unzip && \
    yum clean all && \
    rm -rf /var/cache/yum/*

RUN rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm && \
    yum -y remove php* && \
    yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel

# Swoole extension
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
    cd swoole \
    && phpize \
    && ./configure --enable-async-redis --enable-mysqlnd --enable-openssl --enable-http2 \
    && make -j$(nproc) \
    && make install \
    ) \
    && rm -r swoole \
    && sed -i 'extension=swoole.so' /etc/php.ini 

# Composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer \
    && composer config -g secure-http false \
#    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && composer config -g repo.packagist composer https://packagist.phpcomposer.com \
    && composer self-update --clean-backups

# Install easyswoole
#RUN cd /var/www/code \
#    && composer require easyswoole/easyswoole=${EASYSWOOLE_VERSION} \
#    && php vendor/bin/easyswoole install

EXPOSE 9501

